VirtualBackend#
Options#
From qrisp.interface
is it possible to import the following kind of backends.
Option |
Description |
---|---|
Allows to use a Qiskit Aer backend. |
|
Allows to use a Qiskit Runtime backend, exploiting the Qiskit’s Sampler primitive. |
|
Allows to use an IQM quantum computer as a backend via IQM Resonance. |
- class VirtualBackend(run_func, port=None)[source]#
This class provides a virtual backend for circuit execution. Virtual means that the server is running on the same machine as a separate Python thread. This structure allows setting up convenient wrappers for foreign/ modified circuit dispatching code.
Circuits can be run using
virtual_backend_instance.run(qc)
. The function that should be used to run a circuit can be specified during construction using therun_func
parameter.- Parameters:
- run_funcfunction
A function that recieves a QuantumCircuit, an integer specifiying the amount of shots and a token in the form of a string. It returns the counts as a dictionary of bitstrings.
- namestr, optional
A name for the virtual backend. The default is None.
- portint, optional
The port on which to listen. The default is None.
Examples
We set up a VirtualBackend, which prints the received QuantumCircuit and returns the results of the QASM simulator. It is required that the run_func specifies a default value for the shots parameter.
def run_func(qasm_str, shots = 1000, token = ""): from qiskit import QuantumCircuit qiskit_qc = QuantumCircuit.from_qasm_str(qasm_str) print(qiskit_qc) from qiskit_aer import AerSimulator qiskit_backend = AerSimulator() #Run Circuit on the Qiskit backend return qiskit_backend.run(qiskit_qc, shots = shots).result().get_counts()
>>> from qrisp.interface import VirtualBackend >>> example_backend = VirtualBackend(run_func) >>> from qrisp import QuantumFloat >>> qf = QuantumFloat(3) >>> qf[:] = 4 >>> qf.get_measurement(backend = example_backend) ┌─┐ qf.0: ─────┤M├────── └╥┘┌─┐ qf.1: ──────╫─┤M├─── ┌───┐ ║ └╥┘┌─┐ qf.2: ┤ X ├─╫──╫─┤M├ └───┘ ║ ║ └╥┘ cb_0: 1/══════╩══╬══╬═ 0 ║ ║ cb_1: 1/═════════╩══╬═ 0 ║ cb_2: 1/════════════╩═ {4: 1.0}
Methods#
|